package cn.spark.study.core

import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
/*
 * topn 
 * 1. 构造 (key,value) 的 PairRDD
 * 2. sortByKey
 * 3. take(n) 生成 Array
 * 4. 增强for循环遍历打印
 */
object Top3 {
  def main(args: Array[String]): Unit = {
    val sc = new SparkContext(new SparkConf().setAppName("Top3").setMaster("local"))
    
    val sortLine = sc.textFile("C://Users//e20160504//Desktop//sort.txt", 1).map { lines => (lines.split(" ")(0),lines) }.sortByKey(false, 1).map(_._2).take(3)
    
    for(line<- sortLine){
      println(line)
    }
  }
}